<template>
  <div class="login-container">
        <div class="login-form leftlogin">
          <img src="../../assets/uimg/home_logo.png"/>
          <img class="dklogo" src="../../assets/imgs/dianke_logo.png"/>
        </div>
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
       <div class="lborder">
  <img class="leftup" src="../../assets/uimg/angle_left_up.png" />
  <img class="rightup" src="../../assets/uimg/angle_right_up.png" />
  <img class="leftdow" src="../../assets/uimg/angle_left_down.png" />
  <img class="rightdow" src="../../assets/uimg/angle_right_down.png" />
      <div class="title-container">
        <h3 class="title">用户登录</h3>
      </div>
      <el-form-item prop="username">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          ref="username"
          v-model="loginForm.username"
          placeholder="Username"
          name="username"
          type="text"
          tabindex="1"
          auto-complete="on"
          @keyup.enter.native="handleLogin"
        />
      </el-form-item>

      <!-- <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          :key="passwordType"
          ref="password"
          v-model="loginForm.password"
          :type="passwordType"
          placeholder="Password"
          name="password"
          tabindex="2"
          auto-complete="on"
          @keyup.enter.native="handleLogin"
          style="background-color:transparent"
        />
        <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
        </span>
      </el-form-item> -->
      <el-row :gutter="10">
        <el-col :span='15'>
          <el-form-item>
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.password"
              placeholder="验证码"
              name="password"
              auto-complete="on"
              @keyup.enter.native="handleLogin"
            />
          </el-form-item>
        </el-col>
        <el-col :span='4'>
            <el-button v-show="verShow" type="primary"  @click="_SecurityCode">发送验证码</el-button>
            <el-button disabled="disabled" type="primary" v-show="!verShow">{{timer}}秒重新获取</el-button>
        </el-col>
      </el-row>
       <el-row>
         <el-col :offset="21" :spna='2'>
          <router-link   to="/help" class="loline">帮助</router-link>
         </el-col>
       </el-row>
      <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:20px;" @click.native.prevent="handleLogin">登录</el-button>
       <router-link to="/reg" class="regist">注册</router-link>
      </div>
    </el-form>
    <!-- <br>
    <div><p>建议显示分辨率为1920×1080像素，放缩比列100%。</p></div> -->
  </div>
</template>

<script>
import { validUsername } from '@/utils/validate'
import request2 from "@/utils/request-new";

export default {
  name: 'Login',
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!validUsername(value)) {
        callback(new Error('请输入正确的用户名'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('密码不能少于6位'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined,
      checked:false,
      verShow:true,
      timer:null
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      if(!this.loginForm.username) {
        this.$message.error('请输入用户名')
        return
      }
      if(!this.loginForm.password) {
        this.$message.error('请输入验证码')
        return
      }
      // this.$router.push('/start');
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.loginForm.validate=this.loginForm.password
          this.$store.dispatch('user/login', this.loginForm).then(() => {
            this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    _SecurityCode(){
      let reg = /^1[3-9][0-9]{9}$/;
      if(!reg.test(this.loginForm.username)){
        this.$message.error('请输入手机号')
        return
      }
      request2({
        url:'/platformuser/userValidate',
        method: 'post',
        data:{
          phone:this.loginForm.username
        }
      }).then(response => {
        this.timer=60
        this.setTime();
        // this.loginForm.password=response.data
      }).catch(error=>{
      })
    },
    setTime:function (){
      this.verShow = false;
        var auth_timer = setInterval(()=>{
          this.timer--;
          if(this.timer<=0){
          this.verShow = true;
          clearInterval(auth_timer)
        }
      },1000)
	  },
  }
}
</script>

<style lang="scss">

// $bg:;
$light_gray:#fff;
$cursor: #FFF;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: #111;
    // background-image:
  }
}


/* reset element-ui css */
.login-container {

  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        // box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    // background: rgba(0, 0, 0, 0.1);
     background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    color: #454545;
  }
  .el-checkbox__inner{
    background-color: transparent;
    border: 1px solid #00ccff;
    width: 16px;
    height: 16px;
  }
  .el-checkbox{
    color: #fff
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;



.login-container {
  min-height: 100%;
  width: 100%;
  background:url("../../assets/uimg/home_bg.png") center center no-repeat;
  background-size: 100%;
  display: flex;
  margin: 0 auto;
  justify-content:center;
  // align-items:center

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    overflow: hidden;
    .dklogo{
      position: absolute;
      left: 280px;
      top: 240px;
    }
  }
  .leftlogin{
   padding-top: 240px;
  }
  .lborder{
      height: 415px;
      padding: 20px;
      background-color: rgba(122, 121, 121, 0.1);
      border:2px solid;
      border-image:linear-gradient(to left,rgba(255, 255, 255, 0.1),
      #00ccff,rgba(255, 255, 255, 0.1)) 10 30;

    .leftup{
      position: relative;
      top: -22px;
      left: -22px;
    }
    .rightup{
      position: relative;
      top: -22px;
      left: 387px;
    }
    .leftdow{
      position: relative;
      top: 375px;
      left: -66px;
    }
    .rightdow{
      position: relative;
      top:375px;
      left:345px;
    }
    .loline{
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
      padding: 2px;
      color: #00ccff;
      font-size: 14px;
    }
    .regist{
      display: block;
      text-align: center;
      color: #fff;
      font-size: 14px;
      font-weight: 100
    }
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
